//
//  LSQInterestTooTableViewCell.m
//  Style
//
//  Created by dllo on 15/9/24.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "LSQInterestTooTableViewCell.h"
#import <UIImageView+WebCache.h>
#import <Masonry.h>
@implementation LSQInterestTooTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.labelAuthor = [[UILabel alloc]init];
        [self addSubview:self.labelAuthor];
        self.labelAuthor.font = [UIFont systemFontOfSize:15];
        
        
        self.labelTime = [[UILabel alloc]init];
        [self addSubview:self.labelTime];
        self.labelTime.font = [UIFont systemFontOfSize:11];
        self.labelTime.textColor = [UIColor darkGrayColor];
        
        self.labelContent = [[UILabel alloc]init];
        [self addSubview:self.labelContent];
        self.labelContent.numberOfLines = 0;
        self.labelContent.font =[UIFont systemFontOfSize:15];
        self.labelContent.textColor = [UIColor blackColor];
        
        
        self.imageViewPic = [[UIImageView alloc]init];
        [self addSubview:self.imageViewPic];
        
        self.imageViewTime = [[UIImageView alloc]init];
        [self addSubview:self.imageViewTime];
        self.imageViewTime.image = [UIImage imageNamed:@"time.png"];
        
         self.viewPic = [[UIView alloc]init];
        [self addSubview:self.viewPic];
        self.viewPic.backgroundColor = [UIColor colorWithRed:214.0/ 255 green:214.0 / 255 blue:214.0/255 alpha:0.3];
        self.viewPic.layer.cornerRadius = 5;
        self.viewPic.layer.masksToBounds = YES;
        self.viewPic.layer.borderWidth = 0.5;
        self.viewPic.layer.borderColor = ([UIColor blackColor].CGColor);
      
        
        self.imageViewThumb = [[UIImageView alloc]init];
        [self.viewPic addSubview:self.imageViewThumb];
        
       /*自适应高度*/
        self.imageViewThumb.contentMode = UIViewContentModeScaleAspectFit;
        self.imageViewThumb.autoresizesSubviews = YES;
        self.imageViewThumb.autoresizingMask =
        UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    }
    
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.labelAuthor mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.mas_left).with.offset(20);
        
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width , 30));
        
        make.top.equalTo(self).with.offset(5);

        
    }];
    
    [self.labelTime mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.mas_left).with.offset(40);
        
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width , 20));
        
        make.top.equalTo(self.labelAuthor).with.offset(24);
    }];
    
    [self.imageViewTime mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.mas_left).with.offset(21);
        
        make.size.mas_equalTo(CGSizeMake(16 , 16));
        
        make.top.equalTo(self.labelAuthor).with.offset(26);
        
    }];
    
    //self.imageViewPic.frame = CGRectMake(15, 56, 350, 200);
    

    [self.viewPic mas_remakeConstraints:^(MASConstraintMaker *make) {
        
       
        make.left.equalTo(self.mas_left).with.offset(130);
        
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width - 270 , 160));
        
        make.top.equalTo(self.labelAuthor).with.offset(45);
        
       

        
    }];
    
    [self.imageViewThumb mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        //make.centerY.mas_equalTo(self.viewPic.mas_centerY);
        
         make.left.equalTo(self.viewPic.mas_left).with.offset(2.5);
        
        make.size.mas_equalTo(CGSizeMake(100 , 160));
        
        make.top.equalTo(self.viewPic).with.offset(0);
        
        
    }];
    
    //根据文字的大小,计算出文本的尺寸
    //还需要执行一个尺寸(375,0)
    //第三个参数,计算高度需要根据字体的哪个特征来确定
    //NSLog(@"%lf",self.frame.size.width);
    NSDictionary *fontDic=[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15],NSFontAttributeName, nil];
    CGRect rect = [self.labelContent.text boundingRectWithSize:CGSizeMake(self.frame.size.width - 30 , 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDic context:nil];
 
    [self.labelContent mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15);
        
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width - 30, rect.size.height + 20));
        
        make.top.equalTo(self.imageViewPic).with.offset(207 );
        
        
    }];
    
   
    
}


-(void)setModel:(LSQpushModel *)model
{

    _model = model;
    self.labelAuthor.text = [NSString stringWithFormat:@"from:%@",self.model.author];
    //self.model.author;
    self.labelContent.text = self.model.content;

   
    self.labelTime.text = self.model.time;
    [self.imageViewThumb sd_setImageWithURL:[NSURL URLWithString:self.model.thumb] placeholderImage:[UIImage imageNamed:@"zhanweitu.png"]];

}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
